number_to_words
This function converts an integral number into English words.
string number_to_words(double number, bool include_and)
Parameters:
number
The number to convert.
include_and
A boolean which specifies whether or not the word "and" should be inserted in the appropriate places in the output string.
Return value:
The word representation of the number on success, or an empty string on failure.
Remarks:
This function only works with numbers (positive or negative), without decimals. If the supplied number contains decimals, these will simply be removed without rounding.
If the number is lower than -999999999 (minus nine hundred ninety nine million nine hundred ninety nine thousand nine hundred ninety nine) or greater than 999999999 (nine hundred ninety nine million nine hundred ninety nine thousand nine hundred ninety nine), the function will fail.
This function is very useful when you wish to have a number spoken by using concatenated sound files, for instance. Simply split the words up into an array with the string_split function, and then loop through the resulting array and play an appropriate sound file for each word.
Example:
void main()
{
long my_number=random(-1000, 1000);
string result=number_to_words(my_number, true);
alert("Result", my_number + " is written as " + result + ".");
}